import React from 'react';
import ReactDOM from 'react-dom';

import { HashRouter as Router, Route,Switch } from 'react-router-dom'

import { Provider } from 'mobx-react';
import {openAppLink} from './util/OpenAppLink';

import allStore from './stores';
// import loadjs from 'loadjs'

import { asyncComponent } from 'react-async-component';
import { Tools } from 'weaver-mobile';
import './style';
import { DragDropContextProvider } from 'react-dnd';
import TouchBackend from 'react-dnd-touch-backend';
import openAppLink_old from './util/OpenAppLink_old';
import {openHrmCard} from './util/Utils'
// const getLabel = Tools.getLabel;

const coms = {
  Home: asyncComponent({
    resolve: () => import("./components/main")
  }),
  SystemDoc: asyncComponent({
    resolve: () => import("./components/systemDoc")
  }),
  NetDisk: asyncComponent({
    resolve: () => import("./components/netdisk")
  }),
  NetDiskSearchHistory: asyncComponent({
    resolve: () => import("./components/netdisk/SearchHistory")
  }),
  News: asyncComponent({
    resolve: () => import("./components/news/")
  }),
  NewsSearch: asyncComponent({
    resolve: () => import("./components/news/NewsSearch")
  }),
  Doc: asyncComponent({
    resolve: () => import("./components/doc/")
  }),
  Attach: asyncComponent({
    resolve: () => import("./components/attach/")
  }),
  DocForm: asyncComponent({
    resolve: () => import("./components/docForm/")
  }),
}

class Root extends React.Component {
  
  // // getLocaleLabel = Tools.getLocaleLabel;
  // constructor(props) {
  //   super(props);
  //   this.state = {
  //     loadLang: false
  //   }
  //   // this.getLocaleLabel.bind(this);
  
  // }
  
  // componentDidMount() {
  //   // this.getLocaleLabel('document_mobile', () => {
  //   //   this.setState({loadLang: true});
  //   // });
  //   // Tools.ssoInit().then(() => {
  //   // }).catch((res) => {
  //   //   Bubble.error(getLabel(386481, '登录失败') + "," + JSON.stringify(res), 0);
  //   // });
    
  // }
  
  render() {
    return (
      <Provider {...allStore}>
        <DragDropContextProvider backend={TouchBackend}>
          <Router>
            <Route name="home" path="/" component={() => {
              // if(!this.state.loadLang){
              //   return <div></div>
              // }else{
                return (<coms.Home>
                <Switch>
                  <Route name="systemDoc" path="/systemDoc" component={coms.SystemDoc} />
                  <Route name="netdisk" path="/netdisk" component={coms.NetDisk} />
                  <Route name="netdiskSearchHistory" path="/netdisk/search/history" component={coms.NetDiskSearchHistory} />
                  <Route name="news" path="/news/:scope" component={coms.News} />
                  <Route name="doc" path="/doc/:id" component={coms.Doc} />
                  <Route name="attach" path="/attach/:id" component={coms.Attach} />
                  <Route name="add" path="/add/:scope" component={coms.DocForm} />
                </Switch>
              </coms.Home>)
              // }
            }} />
          </Router>
        </DragDropContextProvider>
      </Provider>
    )
  }
}
Tools.getLocaleLabel('document_mobile', () => {
  ReactDOM.render(<Root />, document.getElementById('root'));
});

window.openAppLink = openAppLink_old;
window.doc_openHrmCard = openHrmCard;
window.openDocumentAppLink = openAppLink;
window.ecCom = {
  WeaRichText: {
    openAppLink: openAppLink
  }
};